/**
 * 详情对话框
 */
var VocManagementLedgerInfoDlg = {
    data: {
        companyId: "",
        isPerfect: "",
        reason: "",
        problem: "",
        rectificationPlan: "",
        createTime: "",
        delFlag: "",
       planTime:""
    }
};

layui.use(['form', 'admin','upload','laydate',  'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload;
    var laydate = layui.laydate;

    //让当前iframe弹层高度适应
    //admin.iframeAuto();


    // 渲染时间选择框
    laydate.render({
        elem: '#planTime'
    });

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/vocManagementLedger/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('vocManagementLedgerForm', result.data);
    if (result.data.isPerfect!=null&&result.data.isPerfect!=""){
        var  sb = document.getElementById("reasons");
        if(result.data.isPerfect == 0){
            sb.style.display = "none"
        } else {
            sb.style.display = "block"
        }
    }

    if (result.data.accessoriesLedger!=null&&result.data.accessoriesLedger!=""){
        $("#accessoriesDetail").attr("value",result.data.accessoriesLedger);
    }
    if (result.data.facilityLedger!=null&&result.data.facilityLedger!=""){
        $("#facilityDetail").attr("value",result.data.facilityLedger);
    }
    if (result.data.dangerLedger!=null&&result.data.dangerLedger!=""){
        $("#dangerDetail").attr("value",result.data.dangerLedger);
    }



    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/vocManagementLedger/editItem", function (data) {
            if(data.code == 200) {
                Feng.success("更新成功！");
            }else{
                Feng.error("更新失败！" + data.message)
            }

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();

        }, function (data) {
            Feng.error("更新失败！" + data.message)
        });

        data.field.accessoriesLedger = $('#accessoriesLedger').val();
        data.field.facilityLedger = $('#facilityLedger').val();
        data.field.dangerLedger = $('#dangerLedger').val();


        ajax.set(data.field);
        ajax.start();

        return false;
    });


    //监听是否完善

    form.on('select(isPerfect)', function (data) {
        console.log(data.elem); //得到select原始DOM对象
        console.log(data.value); //得到被选中的值
        console.log(data.othis); //得到美化后的DOM对象
        var  sb = document.getElementById("reasons");
        console.log(sb); //得到select原始DOM对象n
        if (data.value == 0) {
            sb.style.display = "none"
        }else {
            sb.style.display = "block"
        }
    });



    //
    // //VOCs原辅料台账
    // var uploadInst = upload.render({
    //     elem: '#accessoriesClick'
    //     ,url: Feng.ctxPath+'/ali/uploadFile'
    //     ,before: function(obj){
    //         //预读本地文件示例，不支持ie8
    //         obj.preview(function(index, file, result){
    //             loading = layer.load(0, {
    //                 shade: false,
    //                 time: 10*1000
    //             })
    //         });
    //     }
    //     ,done: function(res){
    //         console.log(res);
    //         layer.close(loading);
    //         $('#accessoriesImg').attr('src', res.data);
    //         $('#accessoriesLedger').attr("value", res.data);
    //         // $("#flowChartImg").after('<input type="hidden" name="flowChart" value="' + res.data + '" />');
    //         //上传成功
    //     }
    //     ,error: function(){
    //         //演示失败状态，并实现重传
    //         var demoText = $('#accessoriesImg');
    //         layer.close(loading);
    //         demoText.html('<span style="color: #FF5722;">上传失败</span> <a '+'class="layui-btn layui-btn-xs demo-reload">重试</ a>');
    //         demoText.find('.demo-reload').on('click', function(){
    //             uploadInst.upload();
    //         });
    //     }
    // });
    //
    //
    //
    // //废气治理设施运行台账
    // var uploadInst = upload.render({
    //     elem: '#facilityClick'
    //     ,url: Feng.ctxPath+'/ali/uploadFile'
    //     ,before: function(obj){
    //         //预读本地文件示例，不支持ie8
    //         obj.preview(function(index, file, result){
    //             loading = layer.load(0, {
    //                 shade: false,
    //                 time: 10*1000
    //             })
    //         });
    //     }
    //     ,done: function(res){
    //         console.log(res);
    //         layer.close(loading);
    //         $('#facilityImg').attr('src', res.data);
    //         $('#facilityLedger').attr("value", res.data);
    //         // $("#flowChartImg").after('<input type="hidden" name="flowChart" value="' + res.data + '" />');
    //         //上传成功
    //     }
    //     ,error: function(){
    //         //演示失败状态，并实现重传
    //         var demoText = $('#facilityImg');
    //         layer.close(loading);
    //         demoText.html('<span style="color: #FF5722;">上传失败</span> <a '+'class="layui-btn layui-btn-xs demo-reload">重试</ a>');
    //         demoText.find('.demo-reload').on('click', function(){
    //             uploadInst.upload();
    //         });
    //     }
    // });
    //
    // //危废台账
    // var uploadInst = upload.render({
    //     elem: '#dangerClick'
    //     ,url: Feng.ctxPath+'/ali/uploadFile'
    //     ,before: function(obj){
    //         //预读本地文件示例，不支持ie8
    //         obj.preview(function(index, file, result){
    //             loading = layer.load(0, {
    //                 shade: false,
    //                 time: 10*1000
    //             })
    //         });
    //     }
    //     ,done: function(res){
    //         console.log(res);
    //         layer.close(loading);
    //         $('#dangerImg').attr('src', res.data);
    //         $('#dangerLedger').attr("value", res.data);
    //         // $("#flowChartImg").after('<input type="hidden" name="flowChart" value="' + res.data + '" />');
    //         //上传成功
    //     }
    //     ,error: function(){
    //         //演示失败状态，并实现重传
    //         var demoText = $('#dangerImg');
    //         layer.close(loading);
    //         demoText.html('<span style="color: #FF5722;">上传失败</span> <a '+'class="layui-btn layui-btn-xs demo-reload">重试</ a>');
    //         demoText.find('.demo-reload').on('click', function(){
    //             uploadInst.upload();
    //         });
    //     }
    // });



    //VOCs原辅料台账
    var uploadInst = upload.render({
        elem: '#accessoriesClick',
        url: Feng.ctxPath+'/ali/uploadFile',
        accept:'file'

        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                loading = layer.load(0, {
                    shade: false,
                    time: 10*1000
                })
            });
        }
        ,done: function(res){
            console.log(res);
            layer.close(loading);
            $('#accessoriesLedger').attr("value", res.data);
            $('#accessoriesDetail').attr('value', res.data);
            Feng.success("上传成功" )
        }
        ,error: function(){
            //演示失败状态，并实现重传
            var demoText = $('#accessoriesLedger');
            layer.close(loading);
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a '+'class="layui-btn layui-btn-xs demo-reload">重试</ a>');
            demoText.find('.demo-reload').on('click', function(){
                uploadInst.upload();
            });
        }
    });


    //废气治理设施运行台账
    var uploadInst = upload.render({
        elem: '#facilityClick',
        url: Feng.ctxPath+'/ali/uploadFile',
        accept:'file'

        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                loading = layer.load(0, {
                    shade: false,
                    time: 10*1000
                })
            });
        }
        ,done: function(res){
            console.log(res);
            layer.close(loading);
            $('#facilityLedger').attr("value", res.data);
            $('#facilityDetail').attr('value', res.data);
            Feng.success("上传成功" )
        }
        ,error: function(){
            //演示失败状态，并实现重传
            var demoText = $('#facilityLedger');
            layer.close(loading);
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a '+'class="layui-btn layui-btn-xs demo-reload">重试</ a>');
            demoText.find('.demo-reload').on('click', function(){
                uploadInst.upload();
            });
        }
    });


    //危废台账
    var uploadInst = upload.render({
        elem: '#dangerClick',
        url: Feng.ctxPath+'/ali/uploadFile',
        accept:'file'

        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                loading = layer.load(0, {
                    shade: false,
                    time: 10*1000
                })
            });
        }
        ,done: function(res){
            console.log(res);
            layer.close(loading);
            $('#dangerLedger').attr("value", res.data);
            $('#dangerDetail').attr('value', res.data);
            Feng.success("上传成功" )
        }
        ,error: function(){
            //演示失败状态，并实现重传
            var demoText = $('#dangerLedger');
            layer.close(loading);
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a '+'class="layui-btn layui-btn-xs demo-reload">重试</ a>');
            demoText.find('.demo-reload').on('click', function(){
                uploadInst.upload();
            });
        }
    });


});